package objects;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

import map.Map;

import ui.MainPanel;

public class MapObject {
	
	Map map;
	
	protected double x, y;
	protected double centerx, centery;
	protected BufferedImage image;
	
	//Konstruktoren
	public MapObject(int x, int y) {
		if(loadImage("resources/capitol.png"))
			centerPos(x, y);
	}
	
	public MapObject(int x, int y, String img) {
		if(loadImage("resources/" + img))
			centerPos(x, y);
	}
	
	//Methoden
	public void setMap(Map map) {
		this.map = map;
	}
	
	public void centerPos(int x, int y) {
		centerx = x;
		centery = y;
		this.x = x - image.getWidth()/2;
		this.y = y - image.getHeight()/2;
	}

	public boolean loadImage(String img) {
		try {
		    this.image = ImageIO.read(new File(img));
		} catch (Exception e) {
			return false;
		}
		return true;
	}
	
	public int getX() {
		return (int)this.x;
	}
	public int getY() {
		return (int)this.y;
	}
	
	public int getCenterX() {
		return (int)this.centerx;
	}
	public int getCenterY() {
		return (int)this.centery;
	}
	
	public BufferedImage getImage() {
		return this.image;
	}
	
	public void draw(Graphics2D g2d) {
		g2d.drawImage(getImage(), getX(), getY(), MainPanel.instance);
	}
	
	public void logic() {		
	}
	
}
